package com.oplink.webems.modules.cfg.utils;

import java.util.ArrayList;
import java.util.List;

import com.oplink.webems.common.utils.SpringContextHolder;
import com.oplink.webems.modules.cfg.entity.CfgNe;
import com.oplink.webems.modules.cfg.entity.CfgSite;
import com.oplink.webems.modules.cfg.entity.CfgSlot;
import com.oplink.webems.modules.cfg.services.CfgNeService;
import com.oplink.webems.modules.cfg.services.CfgSiteService;
import com.oplink.webems.modules.sys.entity.Dict;
import com.oplink.webems.modules.sys.utils.inf.IDict;

/**
 * 
 * Title:
 * Description:
 * Copyright: Copyright (c) 2014
 * Company: Oplink Communications
 * 
 * @author
 * @serialData 2014-9-23 下午2:57:15
 * @version 1.0
 */

public class CfgUtil {
	/**
	 * 站点服务
	 */
	private static CfgSiteService siteSvr = SpringContextHolder.getBean(CfgSiteService.class);

	/**
	 * 网元服务
	 */
	private static CfgNeService neSvr = SpringContextHolder.getBean(CfgNeService.class);

	/**
	 * 获取所有站点字典
	 * 
	 * @return
	 */
	public static List<Dict> getAllSiteDict() {
		List<CfgSite> listTemp = siteSvr.getAllSite();
		List<Dict> listOut = new ArrayList<Dict>();
		for (IDict item : listTemp) {
			Dict dict = new Dict();
			dict.setLabel(item.getLabel());
			dict.setValue(item.getValue());
			listOut.add(dict);
		}
		return listOut;
	}

	/**
	 * 获取所有网元字典
	 * 
	 * @nid 网元id
	 * @return
	 */
	public static List<Dict> getAllNEDict() {
		List<CfgNe> listTemp = neSvr.getAllNe();
		List<Dict> listOut = new ArrayList<Dict>();
		for (IDict item : listTemp) {
			Dict dict = new Dict();
			dict.setLabel(item.getLabel());
			dict.setValue(item.getValue());
			listOut.add(dict);
		}
		return listOut;
	}

	/**
	 * 获取所有槽位字典
	 * 
	 * @nid 网元id
	 * @return
	 */
	public static List<Dict> getAllSlotDict(String nid) {
		List<Dict> listOut = null;
		if (nid != null) {
			List<CfgSlot> listTemp = neSvr.getCfgNe(Long.parseLong(nid)).getSlotlist();
			listOut = new ArrayList<Dict>();
			for (IDict item : listTemp) {
				Dict dict = new Dict();
				dict.setLabel(item.getLabel());
				dict.setValue(item.getValue());
				listOut.add(dict);
			}
		}
		return listOut;
	}
}
